package com.ctshk.app.order.goods.controller;

import com.ctshk.common.annotations.OperationLogAnnotation;
import com.ctshk.common.annotations.SearchHotWord;
import com.ctshk.common.dto.Result;
import com.ctshk.common.enums.OperationLogModel;
import com.ctshk.common.enums.OperationLogType;
import com.ctshk.common.model.PageResponse;
import com.ctshk.rpc.order.goods.dto.resp.CommodityInfoResp;
import com.ctshk.rpc.order.goods.req.CommodityReq;
import com.ctshk.rpc.order.goods.service.ICommodityHomeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 * 商城--搜索
 * </p>
 *
 * @author 黄利斌
 * @date 2021/5/31 10:26 上午
 */
@Api(value = "商城C端搜索",tags = "商城C端搜索")
@RestController
@RequestMapping("/order/commodity/search")
public class OrderCommoditySearchController {

    @DubboReference
    private ICommodityHomeService commodityHomeService;

    @DubboReference
    private ICommodityHomeService iCommodityHomeService;

    @ApiOperation(value = "获取全部商品(分页)", notes = "获取全部商品(分页)")
    @OperationLogAnnotation(operModul = OperationLogModel.GOODS, operType = OperationLogType.QUERY, operTitle = "获取全部商品(分页)", operDesc = "获取全部商品(分页)")
    @PostMapping("/getCommodityAll")
    public Result<PageResponse<CommodityInfoResp>> getCommodityAll(@RequestBody @Valid CommodityReq req){
        return commodityHomeService.getCommodityAll(req.getPage(),req.getSize(),req.getStatusCode());
    }

    @ApiOperation(value = "关键字推荐获取(C端)", notes = "关键字推荐获取(C端)")
    @OperationLogAnnotation(operModul = OperationLogModel.GOODS, operType = OperationLogType.QUERY, operTitle = "关键字推荐获取(C端)", operDesc = "关键字推荐获取(C端)")
    @GetMapping("/recommend")
    public Result<List<String>> recommend(@RequestParam String keyword){
        return iCommodityHomeService.recommend(keyword);
    }

    @ApiOperation(value = "关键字搜索(C端)", notes = "关键字搜索(C端)")
    @OperationLogAnnotation(operModul = OperationLogModel.GOODS, operType = OperationLogType.QUERY, operTitle = "关键字搜索(C端)", operDesc = "关键字搜索(C端)")
    @PostMapping("/keywordSearch")
    @SearchHotWord(operDesc = "搜索热词记录",operTitle = "搜索热词记录")
    public Result<PageResponse<CommodityInfoResp>> keywordSearch(@RequestBody CommodityReq req){
        return iCommodityHomeService.keywordSearch(req.getKeyword(),req.getStatusCode(),req.getPage(),req.getSize());
    }

    @ApiOperation(value = "热门搜索词汇展示(C端)",notes = "热门搜索词汇展示(C端)")
    @OperationLogAnnotation(operModul = OperationLogModel.GOODS, operType = OperationLogType.QUERY, operTitle = "热门搜索词汇展示(C端)", operDesc = "热门搜索词汇展示(C端)")
    @GetMapping("/hot")
    public Result<List<String>> hotWrods(){
        return iCommodityHomeService.hotWrods();
    }

}
